package com.xkdx.guangguang.card;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;

public class CardDetailModule extends AbsModule {
	CardDetail cardDetail;
	List<CardpartDetail> list;
	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getCardDetail")) {
					parseCardDetail(jsonObj.getJSONObject("DetailInfo"));
				}
			}
		} catch (Exception e) {
			throw e;
		}

	}

	
	private void parseCardDetail(JSONObject jsonObject) throws Exception {
		cardDetail=new CardDetail();
		try {
			JSONObject obj=jsonObject.getJSONObject("DetailInfo");
			
			cardDetail.setRegular(obj.getString("Regular"));
			cardDetail.setPicture(obj.getString("Picture"));
			cardDetail.setDiscount(obj.getString("Discount"));
			cardDetail.setStartTime(obj.getString("StartTime"));
			cardDetail.setEndTime(obj.getString("EndTime"));
			
			JSONArray array=(JSONArray)obj.getJSONArray("others");
			list=new ArrayList<CardpartDetail>();
			for (int i = 0; i < array.length(); i++) {
				JSONObject opt=array.getJSONObject(i);
				CardpartDetail cardpartDetail=new CardpartDetail();
				cardpartDetail.setCinfoID(opt.getString("CinfoID"));
				cardpartDetail.setAddress(opt.getString("Address"));
				cardpartDetail.setDistance(opt.getString("Distance"));
				cardpartDetail.setLatitude(opt.getString("Latitude"));
				cardpartDetail.setLongitude(opt.getString("Longitude"));
				cardpartDetail.setPhone(opt.getString("Phone"));
				cardpartDetail.setShopID(opt.getString("ShopID"));
				cardpartDetail.setShopName(opt.getString("ShopName"));
				list.add(cardpartDetail);
				
			}

		} catch (JSONException e) {
			throw e;
		}

	}

}
